package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.vo.GroupVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/7/7
 * @Description:
 */
@RestController
@RequestMapping("group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    @GetMapping
    public List<GroupVO> getList() {

        return groupService.getList();
    }


    @PostMapping
    public Group addGroup(@RequestBody Group group) {

        group.setCreatedate(new Date());

        groupService.save(group);

        return group;
    }


    @GetMapping("{id}")
    public Group getById(@PathVariable("id") Integer id) {

        return groupService.getById(id);
    }

}
